package 剑指offer.zw_63_股票的最大利润;

class Solution {
    public static void main(String[] args) {
        int[] prices = {7, 1, 5, 3, 6, 4};
        int profit = maxProfit(prices);
        System.out.println(profit);
    }

    public static int maxProfit(int[] prices) {
        if (prices.length <= 0) return 0;
        int ans = 0, min = prices[0];
        for (int price : prices) {
            if (price < min) min = price;
            ans = Math.max(ans, price - min);
        }
        return ans;
    }
}
